package com.craftplay.dao;

import com.craftplay.model.Collection;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class CollectionSqlProvider {

    public String insertSelective(Collection record) {
        BEGIN();
        INSERT_INTO("collection");

        if (record.getCollectionId() != null) {
            VALUES("collectionId", "#{collectionId,jdbcType=INTEGER}");
        }

        if (record.getUserId() != null) {
            VALUES("userId", "#{userId,jdbcType=BIGINT}");
        }

        if (record.getUnitId() != null) {
            VALUES("unitId", "#{unitId,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            VALUES("createTime", "#{createTime,jdbcType=INTEGER}");
        }

        return SQL();
    }

    public String updateByPrimaryKeySelective(Collection record) {
        BEGIN();
        UPDATE("collection");

        if (record.getUserId() != null) {
            SET("userId = #{userId,jdbcType=BIGINT}");
        }

        if (record.getUnitId() != null) {
            SET("unitId = #{unitId,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("createTime = #{createTime,jdbcType=TIMESTAMP}");
        }

        WHERE("collectionId = #{collectionId,jdbcType=INTEGER}");

        return SQL();
    }
}